﻿<?php    
   // $name='ad_'.date('Y-m-d_h-m-s')
    //;
      
    $date = getdate();
    $strdate = $date['year'].'-'.$date['mon'].'-'.$date['mday'].'_'.
                $date['hours'].'-'.$date['minutes'].'-'.$date['seconds'];
    $fmtdate = $date['mday'].'/'.$date['mon'].'/'.$date['year'].' '.
                $date['hours'].':'.$date['minutes'].':'.$date['seconds'];
    
    //so dau la mscb- time-bayden(xuat phieu_bd, kqbd)
    $name='b'.$cb['User']['canbo_id'].'_'.$strdate;//date('Y-m-d_h-m-s');
  
 // ini_set('memory_limit','512M');
    $worksheets = '';
    
    // Sheet đầu tiên lưu thông tin của cán bộ
    $rows = $xls->row($xls->hcell('UID').$xls->hcell('CBID').$xls->hcell('Họ tên').$xls->hcell('Thời điểm tải về'));
    $rows .= $xls->row($xls->cell($cb['User']['id']).$xls->cell($cb['User']['canbo_id']).$xls->cell($cb['Canbo']['HOTEN']).$xls->cell($fmtdate));
    $worksheets .= $xls->worksheet('ThongTin', $rows);    
   

    // bang p_dt_bds
    $rows = $xls->row($xls->hcell('id').$xls->hcell('canbo_id').
                            $xls->hcell('bayden_id').$xls->hcell('NGAY_PBD').
                            $xls->hcell('date_sua'));
    foreach ( $pdtbds as $result ):   
     $cells = '';
        $cells .= $xls->Cell($result['p_dt_bds']['id']);
        $cells .= $xls->Cell($result['p_dt_bds']['canbo_id']);
        $cells .= $xls->Cell($result['p_dt_bds']['bayden_id']);
        $cells .= $xls->Cell($result['p_dt_bds']['NGAY_PBD']);
        $cells .= $xls->Cell($result['p_dt_bds']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('pdtbds',$rows);

    
    $rows = $xls->row($xls->hcell('id').$xls->hcell('p_dt_bd_id').
                            $xls->hcell('doituong_id').$xls->hcell('SL_TREN_BD').
                            $xls->hcell('ghichu').
                            $xls->hcell('date_sua'));
    foreach ( $kqbds as $result ):   
    $cells = '';
        $cells .= $xls->Cell($result['kq_bds']['id']);
        $cells .= $xls->Cell($result['kq_bds']['p_dt_bd_id']);
        $cells .= $xls->Cell($result['kq_bds']['doituong_id']);
        $cells .= $xls->Cell($result['kq_bds']['SL_TREN_BD']);
        $cells .= $xls->Cell($result['kq_bds']['ghichu']);
        $cells .= $xls->Cell($result['kq_bds']['date_sua']);
        $rows .= $xls->row($cells);
     endforeach; 
     $worksheets .= $xls->worksheet('kqbds',$rows);


   // If you print the output to the screen set the proper headers
    $xls->setHeader($name);
    
    //Trong truong hop khong muon ma hoa
    echo $xls->workbook($worksheets);
   
   //Trong truong hop muon ma hoa
      
 /*     
    
    $data = $xls->workbook($worksheets); 
    
    $cryptastic = new cryptastic;
    $encData = $cryptastic->encrypt($data, true);
    if($encData === false){
        $session->setFlash('Lỗi mã hóa dữ liệu');
        $this->redirect(array('controller'=>'bks','action'=>'index'));
    }else{
        echo $encData;
    }
   */ 
   
?> 